import {defineStore} from "pinia";
import {getLocalStorage, setLocalStorage} from "@/lib/util";

const usePcUpdateStore = defineStore('pcUpdate', {
    state:()=>({
        // 是否需要更新
        needUpdate:false,
        showUpdate:false,
        version:0,
        isDownloading:false
    }),
    actions:{
        setNeedUpdate(value){
            setLocalStorage('needUpdate',value)
            this.needUpdate=value
        },
        getNeedUpdate(){
            let needUpdateInLocal=null
            if(getLocalStorage('needUpdate')=='true'){
                needUpdateInLocal=true
            }
            if(getLocalStorage('needUpdate')=='false'){
                needUpdateInLocal=false
            }
            if(needUpdateInLocal==null){
                return this.needUpdate
            }else{
                return needUpdateInLocal
            }
        },
        setShowUpdate(value){
            this.showUpdate=value
        },
        setVersion(value){
            setLocalStorage('version',value)
            this.version=value
        },
        getVersion(){
            return getLocalStorage('version') || this.version
        },
        setIsDownloading(value){
            this.isDownloading=value
        },
        getIsdownloading(){
            return this.isDownloading
        }
    }
})

export default usePcUpdateStore
